package com.shop.admin.controller;

import com.shop.admin.entity.RankedPrize;
import com.shop.admin.result.ApiResult;
import com.shop.admin.service.RankedPrizeService;
import com.shop.admin.utils.PageUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Map;

@Api(tags = {"RankedPrizeController"},description = "奖品配送页面所需接口")
@RestController
@RequestMapping("/api/ranked")
public class RankedPrizeController {

    @Resource
    private RankedPrizeService rankedPrizeService;

    //奖品列表查询
    @GetMapping("/list")
    @ApiOperation(value = "获取所有奖品列表",notes = "无需传参")
    public ApiResult list(@RequestParam Map<String, Object> params){
        PageUtils page = rankedPrizeService.rankedPrizeQueryPage(params);
        return ApiResult.ok(page);
    }

    @PostMapping("/saveUpdate")
    @ApiOperation(value = "新增or修改奖品列表",notes = "主键id,奖品类型 1商品 2优惠券,奖励资产 （商品id 或 优惠券批次id),消费排名")
    public ApiResult save(@ApiParam("参数列表为：{\n" +
            "    \"prizeId\":3,\n" +
            "    \"prizeType\":1,\n" +
            "    \"prizeProperty\":21,\n" +
            "    \"consumerRanked\":1\n" +
            "}")@RequestBody RankedPrize rankedPrize){
        rankedPrizeService.saveOrUpdate(rankedPrize);
        return ApiResult.ok("操作成功");
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除奖品列表",notes = "主键id")
    public ApiResult delete(@ApiParam("参数列表为：[3]")@RequestBody Long[] ids){
        rankedPrizeService.removeRankedPrizeByIds(Arrays.asList(ids));
        return ApiResult.ok("删除成功");
    }

}
